package com.class04.controller;

import com.class04.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2024/3/8 14:07
 */
@Controller
@ResponseBody
//@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<User> getUser() {
        String sql = "select * from user";
        List<User> user = jdbcTemplate.query(sql,
                new BeanPropertyRowMapper<>(User.class));
        return user;
    }

}
